package com.iot08.api.config.sms;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.teaopenapi.models.Config;
import com.iot08.api.service.sms.AliYunSmsServiceImpl;
import com.iot08.api.service.sms.IProviderSmsService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author: chenwenjie 
 * @date: 2023/6/29 10:21
 * @param: 
 * @return: 
 **/
@Configuration(proxyBeanMethods = false)
public class AliYunSdkSmsAutoConfiguration {

    @Bean
    @RefreshScope
    @ConfigurationProperties(prefix = "aliyun.sms")
    public AliYunSmsConfig smsConfig() {
        return new AliYunSmsConfig();
    }

    @Bean
    public Client client(AliYunSmsConfig smsConfig) throws Exception {
        Config config = new Config();
        config.setAccessKeyId(smsConfig.getAccessKeyId());
        config.setAccessKeySecret(smsConfig.getAccessKeySecret());
        return new Client(config);
    }

    @Bean
    public IProviderSmsService aliYunSmsService(Client client)  {
        return new AliYunSmsServiceImpl(client);
    }

}
